package com.hsh.erp.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hsh.erp.domain.common.Result;
import com.hsh.erp.domain.dto.ExpressDTO;
import com.hsh.erp.domain.entity.Express;
import com.hsh.erp.domain.vo.ExpressVO;
import com.hsh.erp.init.DataInitializer;
import com.hsh.erp.mapper.ExpressMapper;
import com.hsh.erp.service.ExpressService;
import com.hsh.erp.utils.MyBeanUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author USER
 * @description 针对表【express_company】的数据库操作Service实现
 * @createDate 2024-05-30 15:59:00
 */
@Service
public class ExpressServiceImpl extends ServiceImpl<ExpressMapper, Express>
        implements ExpressService {

    @Resource
    private DataInitializer dataInitializer;

    /**
     * 列表查询
     *
     * @param expressVO
     * @return
     */
    @Override
    public Result<List<ExpressDTO>> getList(ExpressVO expressVO) {
        expressVO.init();
        QueryWrapper wrapper = new QueryWrapper<>()
                .like(Strings.isNotBlank(expressVO.getName()), "name", expressVO.getName())
                .eq(expressVO.getIsDelete() != null, "is_delete", expressVO.getIsDelete());
        List<ExpressDTO> expressDTOList
                = MyBeanUtils.copyList(list(wrapper), ExpressDTO.class);
        return Result.success(expressDTOList);
    }

    /**
     * 修改一条记录
     *
     * @param expressVO
     * @return
     */
    @Override
    public Result updateOne(ExpressVO expressVO) {
        boolean update = updateById(MyBeanUtils.copy(expressVO, Express.class));
        dataInitializer.initExpress();
        return Result.create(update);
    }

    /**
     * 删除一条记录
     *
     * @param expressVO
     * @return
     */
    @Override
    public Result deleteOne(ExpressVO expressVO) {
        return updateOne(expressVO);
    }

    /**
     * 新增一条记录
     *
     * @param expressVO
     * @return
     */
    @Override
    public Result addOne(ExpressVO expressVO) {
        boolean save = save(MyBeanUtils.copy(expressVO, Express.class));
        dataInitializer.initExpress();
        return Result.create(save);
    }


    //============================================私有方法开始============================================
    //============================================私有方法结束============================================
}




